{extend name="public/base"}

{block name="x-body"}
<style>
  #box {
    border: 1px solid #2cbca3;

    padding: 0 20px;

    position: relative;
  }

  #box #editOrder {
    position: absolute;
    right: 0;
    top: 0;

    z-index: 99;
  }

  #box .layui-table {
    border-bottom: 1px solid #e5e5e5;
  }

  #box th {
    background: white;
    color: #656565;
    font-weight: bold;
  }

  #box td div {
    width: 100px;

    display: inline-block;

    color: #999;
    text-align: right;
  }

  #box td span {
    color: black;
  }

  .box_table thead th {
    background: #f2f2f2 !important;

    font-weight: normal;
    font-size: 12px;
    text-align: center;
  }

  .box_table tbody td {
    font-size: 12px;
    text-align: center;
  }

  .layui-table td, .layui-table th {
    font-size: 13px;
  }
</style>
    <div class="x-body">
      <div class="layui-row">
        <div class="layui-col-md8 layui-col-md-offset2" id="box">
          {if $order.order_status == 0 && $order.pay_status == 0 && $order.shipping_status == 0}
          <button class="layui-btn layui-btn" onclick="load_url('{:url(\'orders/order_form\', [\'id\' => $order.id])}')" id="editOrder"><i class="layui-icon">&#xe642;</i>修改订单</button>
          {/if}
          <div class="layui-row">

            <!-- 基本信息 -->
            <table class="layui-table" lay-skin="nob">

              <colgroup>
                <col width="33%">
                <col width="33%">
                <col width="33%">
              </colgroup>
              <thead>
                <tr>
                  <th colspan="3">基本信息</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>
                    <div>订单 ID：</div>
                    <span>{$order.id}</span>
                  </td>
                  <td>
                    <div>订单编号：</div>
                    <span>{$order.order_sn}</span>
                  </td>
                  <td>
                    <div>会员：</div>
                    <span>{$order.username}</span>
                  </td>
                </tr>

                <tr>
                  <td>
                    <div>E-Mail：</div>
                    <span>{$order.email ? $order.email : '无'}</span>
                  </td>
                  <td>
                    <div>电话：</div>
                    <span>{$order.u_mobile ? $order.u_mobile : '无'}</span>
                  </td>
                  <td>
                    <div>应付{$order.integral ? '积分' : '金额'}：</div>
                    <span>{$order.integral ? $order.integral : $order.order_amount}</span>
                  </td>
                </tr>

                <tr>
                  <td>
                    <div>订单状态：</div>
                    <span>
                      {switch name="order.order_status"}
                        {case value="0"}未确定{/case}
                        {case value="1"}已确定{/case}
                        {case value="2"}已收货{/case}
                        {case value="3"}已取消{/case}
                        {case value="4"}已完成{/case}
                        {case value="5"}已作废{/case}
                      {/switch}
                      /
                      {$order.pay_status == 1 ? '已支付' : '未支付'}
                      /
                      {if $order.shipping_status == 1}
                        已发货
                      {elseif $order.shipping_status == 2}
                        部分发货
                      {else /}
                        未发货
                      {/if}
                    </span>
                  </td>
                  <td>
                    <div>下单时间：</div>
                    <span>{$order.add_time|date="Y-m-d H:i"}</span>
                  </td>
                  <td>
                    <div>支付时间：</div>
                    <span>{if $order.pay_time}{$order.pay_time|date="Y-m-d H:i"}{else /}无{/if}</span>
                  </td>
                </tr>

                <tr>
                  <td>
                    <div>支付方式：</div>
                    <span>{$order.pay_name ? $order.pay_name : '无'}</span>
                  </td>
                  <td>
                    <div>发票抬头：</div>
                    <span>{$order.invoice_title ? $order.invoice_title : '无'}</span>
                  </td>
                  <td>
                    <div>纳税人识别号：</div>
                    <span>{$order.taxpayer ? $order.taxpayer : '无'}</span>
                  </td>
                </tr>
              </tbody>
            </table>

            <!-- 收货信息 -->
            <table class="layui-table" lay-skin="nob">
              <colgroup>
                <col width="33%">
                <col width="33%">
                <col width="33%">
              </colgroup>
              <thead>
              <tr>
                <th colspan="3">收货信息</th>
              </tr>
              </thead>
              <tbody>
              <tr>
                <td>
                  <div>收货人：</div>
                  <span>{$order.consignee}</span>
                </td>
                <td>
                  <div>联系方式：</div>
                  <span>{$order.mobile}</span>
                </td>
                <td>
                  <div>邮编：</div>
                  <span>{$order.zipcode}</span>
                </td>
              </tr>
              <tr>
                <td colspan="3">
                  <div>配送方式：</div>
                  <span>{$order.shipping_name ? $order.shipping_name : '无'}</span>
                </td>
              </tr>
              <tr>
                <td colspan="3">
                  <div style="text-align: right;">收货地址：</div>
                  <span>{$order.province} {$order.city} {$order.district} {$order.address}</span>
                </td>
              </tr>
              <tr>
                <td colspan="3">
                  <div>用户留言：</div>
                  <span>{$order.user_note}</span>
                </td>
              </tr>
              </tbody>
            </table>

            <!-- 商品信息 -->
            <table class="layui-table" lay-skin="nob">
              <colgroup>
                <col width="33%">
                <col width="33%">
                <col width="33%">
              </colgroup>
              <thead>
                <tr>
                  <th colspan="3">商品信息</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>
                    <table class="layui-table box_table" lay-skin="line" style="margin: 0;">
                      <thead>
                        <tr>
                          <th>商品编号</th>
                          <th>商品</th>
                          <th>规格属性</th>
                          <th>数量</th>
                          <th>单品价格</th>
                          {if !$order.integral}
                          <th>会员折扣价</th>
                          {/if}
                          <th>单品小计</th>
                        </tr>
                      </thead>
                      <tbody>
                        {volist name="$order.goods" id="v"}
                        <tr>
                          <td>{$v.goods_sn}</td>
                          <td>
                            <img src="{:config('imgRoute')}{$v.original_img}" style="width: 30px; height: 30px;" alt="">
                            {$v.goods_name}
                          </td>
                          <td>{$v.spec_key_name}</td>
                          <td>{$v.goods_num}</td>
                          <td>{$v.goods_integral ? $v.goods_integral : $v.goods_price}</td>
                          {if !$v.goods_integral}
                          <td>{$v.member_goods_price}</td>
                          {/if}
                          <td>{$v.goods_integral ? $v.goods_integral : $v.member_goods_price * $v.goods_num}</td>
                        </tr>
                        {/volist}
                      </tbody>
                    </table>
                  </td>
                </tr>
                <tr>
                  <td colspan="7" style="text-align: right;">
                    订单总额：{if !$order.integral}￥{$order.total_amount}{else /}{$order.integral}{/if}
                  </td>
                </tr>
              </tbody>
            </table>

            <!-- 费用信息 -->
            <table class="layui-table" lay-skin="nob">
              <colgroup>
                <col width="33%">
                <col width="33%">
                <col width="33%">
              </colgroup>
              <thead>
              <tr>
                <th colspan="3">
                  费用信息
                  {if $order.order_status == 0 && $order.pay_status == 0 && $order.shipping_status == 0}
                  <button class="layui-btn layui-btn-normal layui-btn-xs"  onclick="load_url('{:url(\'orders/order_cost\', [\'id\' => $order.id])}')" ><i class="layui-icon">&#xe642;</i>修改费用</button>
                  {/if}
                </th>
              </tr>
              </thead>
              <tbody>
              <tr>
                <td>
                  <div>小计：</div>
                  <span>{$order.integral ? $order.integral : $order.goods_price}</span>
                </td>
                <td>
                  <div>运费：</div>
                  <span>+{$order.shipping_price}</span>
                </td>
                <td>
                  <div>优惠券抵扣：</div>
                  <span>-{$order.coupon_price}</span>
                </td>
              </tr>

              <tr>
                <td>
                  <div>价格调整：</div>
                  <span>{$order.discount >= 0 ? '+' : '-'}{$order.discount}</span>
                </td>
                <td colspan="2">
                  <div>应付：</div>
                  <span>{$order.order_amount}</span>
                </td>
              </tr>
              </tbody>
            </table>

            <!-- 操作信息 -->
            <table class="layui-table" lay-skin="nob">
              <colgroup>
                <col width="33%">
                <col width="33%">
                <col width="33%">
              </colgroup>
              <thead>
              <tr>
                <th colspan="3">操作信息</th>
              </tr>
              </thead>
              <tbody>
                  <tr>
                    <td colspan="3">
                      <form class="layui-form">
                        <input type="hidden" name="status_desc" value="">
                        <input type="hidden" name="order_id" value="{$order.id}">
                        <input type="hidden" name="action_user" value="{$Think.session.user.id}">
                        <div style="width: 100%;">
                          <div style="float: left;">操作备注：</div>
                          <textarea placeholder="请输入操作备注" id="action_note" name="action_note" class="layui-textarea" style="width: 60%; float: left; margin: 0 0 6px 4px;"></textarea>
                        </div>

                        <div>可执行操作：</div>
                        {if $order.order_status != 5}
                          {if $order.order_status != 3 && ($order.pay_status != 1 || $order.order_status == 0)}
                          <button class="layui-btn" lay-filter="add1" lay-submit="" data-name="pay_status" data-val="{$order.pay_status == 1 ? 0 : 1}">{$order.pay_status == 1 ? '设为未付款' : '付款'}</button>
                          {/if}
                          {if $order.pay_status == 1 && $order.order_status == 0}
                            <button class="layui-btn" lay-filter="add1" lay-submit="" data-name="order_status" data-val="1">确定</button>
                          {elseif $order.order_status == 1 && $order.pay_status == 1 /}
                            {if $order.shipping_status != 1}
                              <button class="layui-btn" lay-filter="add1" lay-submit="" data-name="order_status" data-val="0">取消确定</button>
                              <button class="layui-btn" lay-filter="local" lay-submit="">去发货</button>
                            {/if}
                          {/if}
                          <button class="layui-btn" lay-filter="add1" lay-submit="" data-name="order_status" data-val="5">无效</button>
                          {else /}
                          <button class="layui-btn" lay-filter="del" lay-submit="" data-val="{$order.id}">移除</button>
                        {/if}
                      </form>
                    </td>
                  </tr>
              </tbody>
            </table>

            <!-- 操作记录 -->
            <table class="layui-table" lay-skin="nob">
              <colgroup>
                <col width="33%">
                <col width="33%">
                <col width="33%">
              </colgroup>
              <thead>
              <tr>
                <th colspan="3">操作记录</th>
              </tr>
              </thead>
              <tbody>
              <tr>
                <td>
                  <table class="layui-table box_table" lay-skin="line" style="margin: 0;">
                    <thead>
                    <tr>
                      <th>操作者</th>
                      <th>操作时间</th>
                      <th>订单状态</th>
                      <th>付款状态</th>
                      <th>发货状态</th>
                      <th>描述</th>
                      <th>备注</th>
                    </tr>
                    </thead>
                    <tbody>
                      {volist name="order.action" id="v"}
                      <tr>
                        <td>{if $v.action_user == 0}用户：{$order.username}{else /}管理员：{$v.username}{/if}</td>
                        <td>{$v.log_time|date="Y-m-d H:i"}</td>
                        <td>{if $v.order_status == 1}已确定{elseif $v.order_status == 5 /}废除订单{else /}待确定{/if}</td>
                        <td>{$v.pay_status == 1 ? '已支付' : '未支付'}</td>
                        <td>{$v.shipping_status == 1 ? '已发货' : '未发货'}</td>
                        <td>{$v.status_desc}</td>
                        <td>{$v.action_note}</td>
                      </tr>
                      {/volist}
                    </tbody>
                  </table>
                </td>
              </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>

<script>
    $(function (){
        layui.use('form', function(){
            var form = layui.form;

            form.on('submit(add1)', function(data){
                let url = "{:url('orders/order_cat')}";
                let json = data.field;
                let name = data.elem.dataset.name;
                let code = data.elem.dataset.val;

                json.pay_status = '{$order.pay_status}';
                json.order_status = '{$order.order_status}';
                json.shipping_status = '{$order.shipping_status}';

                let status_desc = '';
                switch (name){
                    case 'order_status':
                        status_desc = code == 1 ? '确认订单' :  code == 0 ? '取消确定' : '废除订单';
                        break;
                    case 'pay_status':
                        status_desc = code == 1 ? '付款成功' : '取消付款';
                        break;
                    case 'shipping_status':
                        status_desc = code == 1 ? '确认发货' : '取消发货';
                        break;
                }

                json[name] = code;
                json.status_desc= status_desc;

                data.field.__token__ = $("input[name='__token__']",top.window.document).val();
                $.post(url, data.field, function(res){
                    if(res.code == 0){
                        dialog(res.msg, false, 0, function (){
                            $("input[name='__token__']",top.window.document).val(res.data.token);
                        });
                    }else if(res.code == 1){
                        dialog(res.msg, res.url, 0, function (){
                            $("input[name='__token__']",top.window.document).val(res.data.token);
                        }, true);
                    }
                }, 'json');

                return false;
            });

            form.on('submit(del)', function(data){
                let url = "{:url('orders/order_del')}";

                let json = {};
                json['__token__'] = $("input[name='__token__']",top.window.document).val();
                json.order_id = data.elem.dataset.val;
                json.action_user = data.field.action_user;
                json.pay_status = '{$order.pay_status}';
                json.order_status = '{$order.order_status}';
                json.shipping_status = '{$order.shipping_status}';

                json.status_desc= '删除订单';

                $.post(url, json, function(res){
                    if(res.code == 0){
                        dialog(res.msg, false, 0, function (){
                            $("input[name='__token__']",top.window.document).val(res.data.token);
                        });
                    }else if(res.code == 1){
                        dialog(res.msg, res.url, 0, function (){
                            parent.location.reload();
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        }, true);
                    }
                }, 'json');

                return false;
            });

            form.on('submit(local)', function(data){
                window.location.href = '{:url("orders/order_deliver", ["id" => $order.id])}';

                return false;
            });
        });
    })

</script>
{/block}